package com.xx.cloud.pay.config.pay;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.xx.cloud.pay.entity.WxPayConf;

import org.springframework.context.annotation.Configuration;

@Configuration
public class MyPayConfig {


    /**
     * TODO 通用支付配置
     * @param wxPayConf
     * @return
     */
    public static WxPayService WxPayService(WxPayConf wxPayConf) {

        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(wxPayConf.getAppId());
        payConfig.setApiV3Key(wxPayConf.getApiV3Key());
        payConfig.setMchId(wxPayConf.getMchId());
        payConfig.setMchKey(wxPayConf.getMchKey());

//        payConfig.setKeyString(FileUtils.requestUrlToBase64(wxPayConf.getKeyPath()));
        payConfig.setNotifyUrl(payConfig.getNotifyUrl());
        payConfig.setKeyPath("D:\\my-pay\\1262349\\12623497\\apiclient_cert.p12"); //服务器配置
        payConfig.setPrivateKeyPath("D:\\my-pay\\1262349\\12623497\\apiclient_key.pem");
        payConfig.setPrivateCertPath("D:\\my-pay\\1262349\\12623497\\apiclient_cert.pem");

        payConfig.setSignType(payConfig.getTradeType());

        payConfig.setCertSerialNo(payConfig.getCertSerialNo());

        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig);
        return wxPayService;

    }
}